<template>
	<view class="sendSubmitOrder">
		<view class="sendSubmitOrder-content">
			<view class="sendSubmitOrder-content-top">
				<text class="addCar-phone">物料信息：</text>
				<view class="addCar-phone-placeholder" @click="show = true">{{ msgobj.wllxName }}</view>
				<u-picker @confirm="bindPickerWlChange" mode="selector" v-model="show" :range="formattedArray"
					range-key="text"></u-picker>
			</view>
			<view class="sendSubmitOrder-content-top">
				<view>
					厂家：{{ msgobj.SETTB99CA00 }}
				</view>
			</view>
			<view class="sendSubmitOrder-content-top">
				<view>
					站点地：{{ materInfo.ORMTB493CA01 }}
				</view>
			</view>
			<view class="sendSubmitOrder-content-top">
				<view>
					站点与厂家距离(km)：{{ msgobj.mail }}
				</view>
			</view>
			<view class="sendSubmitOrder-content-top">
				<view class="flex">运费单价(元/吨)：{{ msgobj.yf }}
					<text>(以实际卸货重量为准)</text>
				</view>
			</view>
		</view>
		<view class="zhujie">
			<view style="color:red">注：{{ REMARK }}</view>
		</view>
		<view class="sendSubmitOrder-nav-bottom">
			<view class="sendSubmitOrder-nav-bottom-l">
				<view class="">
					需冻结保证金：<text>￥{{ ddMasgObj.SUM }}</text>
				</view>
			</view>
			<view class="sendSubmitOrder-nav-bottom-r">
				<button type="default" @click="submitOrderTap">确认接单</button>
			</view>
		</view>
		<u-modal v-model="submitShow" :show-cancel-button="true" @confirm="submitConfirm">
			<view class="slot-content">订单需冻结保证金为：
				<label>{{ ddMasgObj.SUM }}</label>元，{{ msgJDBZ }}
			</view>
		</u-modal>
		<u-toast ref="uToast" />
	</view>
</template>

<script>
export default {
	data() {
		return {
			show: false,
			wlArray: [],
			msgobj: {
				wllxName: '请选择物料', //物料名字
			},
			sendobj: JSON.parse(uni.getStorageSync('sendobj')),
			materInfo: JSON.parse(uni.getStorageSync('materInfo')),
			userinfo: JSON.parse(uni.getStorageSync('userinfo')),
			ddMasgObj: {},
			submitShow: false,
			repeatSubmit: false,
			REMARK: '',
			msgJDBZ: '',
		}
	},
	watch: {

	},
	computed: {
		formattedArray() {
			return this.wlArray.map(item => ({
				text: `${item.SETTB109CA00}-${item.SETTB99CA00}-${item.yf}元-${item.mail}km`,
				...item
			}));
		}
	},
	onShow() {

	},
	onLoad(options) {
		this.preAcceptCjList()
		this.querJDBZMsag()
	},
	methods: {
		preAcceptCjList() {
			uni.showLoading({
				title: '加载中...',
				mask: true
			});
			uni.request({
				url: this.baseUrl + '/orm/ormtb493/preAcceptCjList',
				method: 'POST',
				dataType: 'json',
				data: {
					ORMTB493ID: this.materInfo.ORMTB493ID, //需求iD
					ORMTB410CA00: this.sendobj.ORMTB410ID, // 接单人ID
				},
				success: (res) => {
					uni.hideLoading();
					if (res.data.code == 200) {
						this.wlArray = res.data.data
						console.log('this.wlArray', this.wlArray)
					} else {
						this.$refs.uToast.show({
							title: res.data.message,
							type: 'default',
							icon: false
						})
					}
				},
				fail: (res) => {
					uni.hideLoading();
					this.$refs.uToast.show({
						title: res.errMsg,
						type: 'default',
						icon: false
					})
				}
			});
		},
		bindPickerWlChange(e) {
			// console.log(e,`output->e`, e)
			let index = e[0]
			this.msgobj = this.wlArray[index]
			this.msgobj.wllxName = this.wlArray[index].SETTB206CA01
			this.queryddMsag()
		},
		submitOrderTap() {
			if (this.msgobj.wllxName == '请选择物料') {
				uni.showToast({
					title: '请选择物料',
					duration: 5000,
					icon: 'none',
				})
				return
			}
			if (this.repeatSubmit) {
				uni.showToast({
					title: '订单已提交请勿重复提交！！',
					duration: 5000,
					icon: 'none',
				});
				return
			}
			this.submitShow = true
		},
		submitConfirm() {
			this.repeatSubmit = true
			uni.showLoading({
				title: '请求中...',
				mask: true
			});
			// console.log(this.sendobj)
			let carList = []
			this.sendobj.carList.forEach((item, index) => {
				carList.push({
					carPlate: item.carPlate,
					weight: item.ORDTB400CA07
				})
			});
			console.log(carList)
			uni.request({
				url: this.baseUrl + '/orm/ormtb493/acceptOrmtb493',
				method: 'POST',
				dataType: 'json',
				data: {
					PERTB005ID: this.sendobj.PERTB005ID,
					ORMTB410CA00: this.sendobj.ORMTB410ID, // 接单人ID
					ORMTB460ID: this.materInfo.ORMTB493ID, //需求iD
					ORMTB410ID: this.sendobj.ORMTB410ID, // 接单人ID
					ORMTB493CA05: this.materInfo.ORMTB493CA05, //物料类型编号
					ORMTB470CA04: this.msgobj.SETTB99ID, //厂家长id
					ORMTB470CA15: this.msgobj.SETTB100ID, //厂家短id
					ORMTB470CA06: this.msgobj.SETTB109ID, //物料id
					ormtb461List: carList,  //车辆信息
				},
				success: (res) => {
					console.log(res);
					if (res.data.code == 200) {
						uni.switchTab({
							url: '/pages/tabbar/receivingOrder/receivingOrder'
						})
						uni.removeStorageSync('materInfo')
						uni.removeStorageSync('sendobj')
						uni.showToast({
							title: '接单成功',
							duration: 5000,
							icon: 'none',
						});
					} else {
						uni.showToast({
							title: res.data.message,
							type: 'default',
							icon: false
						})
					}
					this.repeatSubmit = false
					uni.hideLoading();
				},
				fail: (res) => {
					uni.showToast({
						title: res.errMsg,
						type: 'default',
						icon: false
					})
					uni.hideLoading();
				}
			});
		},
		//查询冻结保证金
		queryddMsag() {
			uni.showLoading({
				title: '加载中...',
				mask: true
			});
			uni.request({
				url: this.baseUrl + '/orm/ormtb470/calcOrder493',
				method: 'POST',
				dataType: 'json',
				data: {
					ORMTB493ID: this.materInfo.ORMTB493ID, //需求iD
					ORMTB410ID: this.sendobj.ORMTB410ID, // 接单人ID
					ormtb461List: this.sendobj.carList,  //车辆信息
					ORMTB493CA05: this.materInfo.ORMTB493CA05, //物料类型编号
					ORMTB470CA04: this.msgobj.SETTB99ID, //厂家长id
					ORMTB470CA15: this.msgobj.SETTB100ID, //厂家短id
					ORMTB470CA06: this.msgobj.SETTB109ID, //物料id
				},
				success: (res) => {
					uni.hideLoading();
					if (res.data.code == 200) {
						console.log(res.data.data)
						if (res.data.data) {
							this.ddMasgObj = res.data.data
						}
					} else {
						this.$refs.uToast.show({
							title: res.data.message,
							type: 'default',
							icon: false
						})
					}
				},
				fail: (res) => {
					uni.hideLoading();
					this.$refs.uToast.show({
						title: res.errMsg,
						type: 'default',
						icon: false
					})
				}
			});
		},
		//查询接单取消时间备注
		querJDBZMsag() {
			uni.showLoading({
				title: '加载中...',
				mask: true
			});
			uni.request({
				url: this.baseUrl + '/orm/ormtb493/getRemark2',
				method: 'POST',
				dataType: 'json',
				data: {
					ORMTB493ID: this.materInfo.ORMTB493ID, //需求iD
				},
				success: (res) => {
					uni.hideLoading();
					if (res.data.code == 200) {
						if (res.data.data) {
							this.msgJDBZ = res.data.data.REMARK2
							this.REMARK = res.data.data.REMARK
						}
					} else {
						this.$refs.uToast.show({
							title: res.data.message,
							type: 'default',
							icon: false
						})
					}
				},
				fail: (res) => {
					uni.hideLoading();
					this.$refs.uToast.show({
						title: res.errMsg,
						type: 'default',
						icon: false
					})
				}
			});
		},
	}
}
</script>

<style lang="scss" scoped>
.sendSubmitOrder {
	width: 100vw;
	min-height: 100vh;
	background-color: #e3e3e3;
}

.sendSubmitOrder .slot-content {
	padding: 20rpx 30rpx;
}

.sendSubmitOrder .slot-content label {
	color: red;
}

.sendSubmitOrder-sal-type {
	display: flex;
	background-color: #FFF;
}

.sendSubmitOrder-sal-type-text {
	height: 90rpx;
	line-height: 90rpx;
	padding: 0 10rpx 0 20rpx;
}

.sendSubmitOrder-sal-type-radio {
	margin-left: 40rpx;
	padding: 20rpx 0;
}

.sendSubmitOrder-address {
	display: flex;
	background-color: #FFF;
	margin-top: 10rpx;
	padding: 10px 0;
}

.sendSubmitOrder-address text {
	text-align: center;
}

.sendSubmitOrder-address .iconweizhi {
	width: 100rpx;
	display: flex;
	align-items: center;
	color: #007AFF;
	padding-left: 50rpx;
}

.sendSubmitOrder-address-info {
	display: flex;
	align-items: center;
}

.sendSubmitOrder-title {
	height: 70rpx;
	line-height: 70rpx;
	padding-left: 30rpx;
	color: #333;
	font-size: 30rpx;
	background-color: #FFF;
}

.sendSubmitOrder-content {
	margin-bottom: 60rpx;
	margin-top: 10rpx;
}

.sendSubmitOrder-content-top {
	display: flex;
	// justify-content: space-between;
	align-items: center;
	height: 80rpx;
	line-height: 80rpx;
	padding-left: 30rpx;
	padding-right: 30rpx;
	color: #333;
	font-size: 36rpx;
	margin-bottom: 2rpx;
	background-color: #FFF;

	.addCar-phone-placeholder {
		width: 100%;
		flex: 1;
	}

	.flex {
		display: flex;
		align-items: center;
		justify-content: space-between;
		width: 100%;

		text {
			color: #888;
			font-size: 28rpx;
		}
	}
}

.sendSubmitOrder-content-p {
	padding: 30rpx;
	background-color: #FFF;
}

.sendSubmitOrder-content-p-li {
	display: flex;
	justify-content: space-between;
	/* font-size: 26rpx; */
	color: #333;
}

.sendSubmitOrder-content-p-li+.sendSubmitOrder-content-p-li {
	margin-top: 30rpx;
}

.sendSubmitOrder-content-p-li text {
	color: #999;
}

.sendSubmitOrder-content-p-li view {
	flex: 1;
	text-align: right;
}

.sendSubmitOrder-content-bottom {
	display: flex;
	justify-content: space-between;
	height: 80rpx;
	line-height: 80rpx;
	background-color: #FFF;
	font-size: 30rpx;
	color: #333;
	padding: 0 30rpx;
}

.sendSubmitOrder-content-bottom view {
	flex: 1;
	text-align: right;
	padding: 0 20rpx;
	color: red;
}

.sendSubmitOrder-nav-bottom {
	position: fixed;
	bottom: 0;
	left: 0;
	display: flex;
	width: 100%;
	height: 120rpx;
	background-color: #FFF;
	z-index: 2;
	display: flex;
	align-items: center;
	justify-content: space-between;
}

.sendSubmitOrder-nav-bottom-l {
	padding-left: 30rpx;
	color: #333;
}

.sendSubmitOrder-nav-bottom-l view {
	/* font-size: 30rpx; */
}

.sendSubmitOrder-nav-bottom-l>view>text {
	color: red;
	font-size: 40rpx;
}

.sendSubmitOrder-nav-bottom-l>text {
	font-size: 24rpx;
	color: #999;
}

.sendSubmitOrder-nav-bottom-r button {
	height: 120rpx;
	line-height: 120rpx;
	background-color: #02a2f4;
	color: #FFF;
}

.zdy-ty-xz {
	color: #e3e3e3 !important;
	font-size: 14rpx;
}

.zhujie {
	padding: 0 20rpx;
}
</style>
